﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SmartMD.DataAccess.Service;
using System.Collections.ObjectModel;
using SmartMD.DataModel.Entity;
using Techstar.Dialog;
using System.Xml;
using SmartMD.Manager.Utils;
using SmartMD.Manager.Container;

namespace SmartMD.Manager.Container
{
    /// <summary>
    /// Interaction logic for ContainerModelMaintain.xaml
    /// </summary>
    public partial class ContainerModelMaintain : BaseWindow
    {
        private ObservableCollection<ContainerModelEntity> _cmList = null;

        public ContainerModelMaintain()
        {
            InitializeComponent();
            this.RegisterToolbar(this.MyToolbar);

            _cmList = DataServiceManager.ContainerModelService.loadAllContainerModels();
            lvContainerModel.ItemsSource = _cmList;

            this.Title = "容器模型维护";
        }

        public static string ModuleName { get { return "容器模型维护"; } }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
        }

        private void txtSearch_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            ContainerModelEntity item = (ContainerModelEntity)lvContainerModel.SelectedItem;
            MainWindow.Show(ContainerModelPanel.ModuleName);
            //ContainerModelPanel.LoadModel(item.StyleFile, item.Name)
            ContainerModelPanel.LoadModel(item/*.StyleFile, item.Name */);
            ContainerModelPanel.IsEdit = true;
            ContainerModelPanel.EditCME = item;
        }

        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.Show(ContainerModelPanel.ModuleName);
            ContainerModelEntity item = (ContainerModelEntity)lvContainerModel.SelectedItem;
            ContainerModelPanel.ClearModel();
        }

        private void btnDele_Click(object sender, RoutedEventArgs e)
        {
            ContainerModelEntity item = (ContainerModelEntity)lvContainerModel.SelectedItem;

            if (_cmList.IndexOf(item) >= 0)
            {
                _cmList.Remove(item);
                DataServiceManager.ContainerModelService.DeleteObjectById(item.Id);
            }
            else
            {
                TaskDialogEx.Information("提示", "请选择要删除的条目.");
            }
        }

        private void btnRefresh_Click(object sender, RoutedEventArgs e)
        {
            _cmList = DataServiceManager.ContainerModelService.loadAllContainerModels();
            lvContainerModel.ItemsSource = _cmList;
        }


        private void lvContainerModel_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            MainWindow.Show(ContainerModelPanel.ModuleName);
            ContainerModelEntity item = (ContainerModelEntity)lvContainerModel.SelectedItem;
            //ContainerModelPanel.LoadModel(item.StyleFile, item.Name)
            ContainerModelPanel.LoadModel(item/*.StyleFile, item.Name */);
            ContainerModelPanel.IsEdit = true;
            ContainerModelPanel.EditCME = item;
        }
    }
}
